import java.util.Random;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-09-18
 * Time:16:56
 */
public class Java_1 {

    public static long num1,num2;
    public static void odd(int num)
    {
        num1+=num;
    }
    public static void add(int num)
    {
        num2+=num;
    }

    public static void main(String[] args) throws InterruptedException {
        Random r=new Random();
        int total=1000000;
        int[] array=new int[total];
        for(int i=0;i<total;i++)
        {
            int num= r.nextInt(100)+1;
            array[i]=num;
        }
        long start = System.currentTimeMillis();
       Thread t1=new Thread(()->{
          for (int i=0;i<total;i+=2)
          {
              odd(array[i]);
          }
       });
        Thread t2=new Thread(()->{
            for (int i=1;i<total;i+=2)
            {
                add(array[i]);
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        long end = System.currentTimeMillis();
        System.out.println(num1+num2);
        System.out.println("时间为:"+(end-start));
    }
}
